import { DynamicModule, Module } from '@nestjs/common';
import { MulterModule } from '@nestjs/platform-express'
import { ConfigService } from '@nestjs/config'

export interface AppUploadModuleOptions {
  destination: string
}
@Module({})
export class AppUploadModule {
  static register(options: AppUploadModuleOptions): DynamicModule {
    const { destination } = options
    return {
      module: AppUploadModule,
      imports: [
        MulterModule.registerAsync({
          inject: [ConfigService],
          useFactory: (configService) => ({
            dest: configService.get(destination)
          })
        })
      ],
      exports: [MulterModule]
    }
  }
}
